package org.erp.procurement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.erp.common.enums.SysWhetherEnum;
import org.erp.procurement.entity.OrderProductDetails;
import org.erp.procurement.entity.ProductReport;
import org.erp.procurement.mapper.ProductReportMapper;
import org.erp.procurement.service.OrderProductDetailsService;
import org.erp.procurement.service.ProductReportService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author libin
 * @version 1.0
 * @description:
 * @date 2025/11/6 11:36
 **/
@Log4j2
@Service
@AllArgsConstructor
public class ProductReportServiceImpl extends ServiceImpl<ProductReportMapper, ProductReport> implements ProductReportService {

    private final OrderProductDetailsService orderProductDetailsService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void reportSave(ProductReport productReport) {
        OrderProductDetails orderProductDetails = orderProductDetailsService.getById(productReport.getProductId());
        orderProductDetails.setCheckStatus(SysWhetherEnum.YES.getCode());
        orderProductDetailsService.updateById(orderProductDetails);
        this.save(productReport);
    }

    @Override
    public ProductReport findByProductId(Long productId) {
        return this.getOne(new QueryWrapper<ProductReport>().lambda()
                .eq(ProductReport::getProductId,productId));
    }
}
